/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view

class Order {
    //default prices for each wood
    def prices=["cherry":5.95, "maple":6.00, "mahogany":9.60,
        "wenge":22.35, "whiteoak":6.70, "sawdust":1.50]
    //default delivery time for each wood
    def time=["cherry":0.5, "maple":1.5, "mahogany":3.0,
        "wenge":5.0, "whiteoak":1.5, "sawdust":0]
    
    //name and address of buyer
    def name
    def address
    
    def quantity             //quantity of wood ordered in B.F
    def orderPrice=[:]       //Prices for every wood in order
    def totalOrderPrice=0.0  //total price of order
    def orderTime=[:]        //Delivery time for every wood in order
    def totalOrderTime=0.0   //total delivery time of order
    
    //calculate the price for every wood and the total price of order
    def calculatePrice() {
        totalOrderPrice=0.0
        quantity.each { orderPrice[it.key]= it.value*prices[it.key]
            totalOrderPrice+=orderPrice[it.key]
        }
    }
    
    //calculate the delivery time for every wood and the total delivery time of order
    def boolean deliveryTime() {//woody.calculatePrice();
        totalOrderTime=0.0
        try {quantity.each {
            switch (it.value) {
                case 0: orderTime[it.key]=0
                    break
                case 1..100: orderTime[it.key]=time[it.key]
                    break
                case 101..200: orderTime[it.key]=2*time[it.key]
                    break
                case 201..300: orderTime[it.key]=3*time[it.key]
                    break
                case 301..400: orderTime[it.key]=4*time[it.key]
                    break
                case 401..500: orderTime[it.key]=5*time[it.key]
                    break
                case 501..1000: orderTime[it.key]=5.5*time[it.key]
                    break
                default: throw Exception
            }
            if(orderTime[it.key]>totalOrderTime) totalOrderTime=orderTime[it.key]
        }}catch(Exception e){return false}
        return true
    }
}